<template>
  <div id="app" v-loading.fullscreen.lock="loading">
    <router-view />
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import { initConfigData, login, setAuth } from "./utils/http";

export default {
  data() {
    return {
      loading: false,
    };
  },
  computed: {
    ...mapGetters(["token", "isLogin"]),
  },
  mounted() {
    if (this.isLogin) {
      let url = this.$route.query.to || "index";
      this.$router.push({
        name: url,
      });
    } else {
      let token =
        this.$route.query.token || "25e30ea0-ef0e-494d-b20b-cff465854057";
      let url = this.$route.query.to || "index";
      setAuth(token);
      initConfigData("BASE").then((res) => {
        if (res.code === 0) {
          this.$store.commit("login", {
            token: token,
            roleSet: [
              {
                name: "管理员",
              },
            ],
            username: "cveo",
            idNumber: "",
            phone: "cveo",
          });
          this.$message.success("初始化数据成功！");
          this.$router.push({
            name: url,
          });
        } else {
          this.$message.error("初始化数据失败！");
        }
      });
    }
  },
};
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  border: 0;
  padding: 0;
  margin: 0;
}

body {
  border: 0;
  padding: 0;
  margin: 0;
}
</style>
